//
//  GKZYSortMajorDetailViewController.m
//  GKZYAid
//
//  Created by tony on 16/3/4.
//  Copyright © 2016年 GKZYAid. All rights reserved.
//

#import "GKZYSortMajorDetailViewController.h"
#import "MyDefine.h"
#import "MajorButtonView.h"
#import "GKZYSortLeftBarButtonItemView.h"
#import <AFNetworking.h>
#import "Urls.h"
#import "GKZYMajorDetailHeaderView.h"
#import "GKZYMajorDetailTableViewCell.h"
#import "GKZYMajorDetailModel.h"
#import "GKZYSimilarMajorModel.h"
#import "GKZYMajorDetailTopView.h"
#import "GKZYMajorEmploymentTableViewCell.h"
#import "EmploymentDictionaryModel.h"
#import "Industry_info_listModel.h"
#import "City_listModel.h"
#import "Major_salary_year_listModel.h"
#import "GKZYUserSortDataHandel.h"
#import "GKZYRecommentSchoolModel.h"
#import "GKZYRecommendTableViewCell.h"
#import "GKZYUniversityDetailController.h"
#import "MBProgressHUD.h"


//Tag  值  200开始

@interface GKZYSortMajorDetailViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>{
    
    MBProgressHUD *HUD;
}


//界面顶部视图
@property(nonatomic,strong)GKZYMajorDetailTopView *topView;
//返回按钮
@property(nonatomic,strong)UILabel *backLabel;

//专业介绍按钮
@property(nonatomic,strong)MajorButtonView *introduce;
//专业就业按钮
@property(nonatomic,strong)MajorButtonView *employment;
//推荐按钮
@property(nonatomic,strong)MajorButtonView *recommend;

//切换tableview的scroll
@property(nonatomic,strong)UIScrollView *scroll;


#pragma mark +++++++++++   专业介绍   +++++++++++++++
//专业介绍tableview
@property(nonatomic,strong)UITableView *detailMajorTableView;
//专业介绍是收起还是展开
@property(nonatomic,assign)BOOL openOrPickUp;
//专业详情
@property(nonatomic,strong)GKZYMajorDetailModel *majorDetailInfo;
//相近专业
@property(nonatomic,strong)NSMutableArray *similarDataArray;
//专业简介view，设置为tableview的headerviewforsection
@property(nonatomic,strong)GKZYMajorDetailHeaderView *headerView;

#pragma mark +++++++++++++   就业    +++++++++++++++
//就业tableview
@property(nonatomic,strong)UITableView *employmentTV;
@property(nonatomic,strong)EmploymentDictionaryModel *dataDictionary;
@property(nonatomic,strong)NSMutableArray *majorSalaryArray;
@property(nonatomic,strong)NSMutableArray *industryArray;
@property(nonatomic,strong)NSMutableArray *cityArray;

#pragma mark +++++++++++    推荐学校    ++++++++++++++

@property(nonatomic,strong)UITableView *recommendTableView;
@property(nonatomic,strong)NSMutableArray *recommendArray;


@end


@implementation GKZYSortMajorDetailViewController

-(void)loadView{
    [super loadView];
    self.view.backgroundColor = CustomGrayColor;
    self.topView = [[GKZYMajorDetailTopView alloc]initWithFrame:CGRectMake(0, 0, VCWIDTH, VCHEIGHT/3)];
    [self.topView setTheMajorName:self.model.major_name andCode:[NSString stringWithFormat:@"%@",self.model.major_code]];
    [self.view addSubview:self.topView];

    self.introduce = [[MajorButtonView alloc]initWithFrame:CGRectMake(0, VCHEIGHT/3, VCWIDTH/3, 40)];
    [self.introduce setTheTitle:@"简介"];
    self.introduce.backgroundColor = [UIColor whiteColor];
    [self.introduce setTheTitleColor:[UIColor orangeColor] andMarkColor:[UIColor orangeColor]];
    [self.view addSubview:self.introduce];
    
    self.employment = [[MajorButtonView alloc]initWithFrame:CGRectMake(VCWIDTH/3, VCHEIGHT/3, VCWIDTH/3, 40)];
    [self.employment setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
    [self.employment setTheTitle:@"就业"];
    self.employment.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.employment];
    
    self.recommend = [[MajorButtonView alloc]initWithFrame:CGRectMake(VCWIDTH*2/3, VCHEIGHT/3, VCWIDTH/3, 40)];
    [self.recommend setTheTitle:@"推荐学校"];
    self.recommend.backgroundColor = [UIColor whiteColor];
    [self.recommend setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
    [self.view addSubview:self.recommend];
    
    //添加手势
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(introduceTB)];
    [self.introduce addGestureRecognizer:tap1];
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(employmentTB)];
    [self.employment addGestureRecognizer:tap2];
    
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(recommendTB)];
    [self.recommend addGestureRecognizer:tap3];
    
    self.scroll =[ [UIScrollView alloc]initWithFrame:CGRectMake(0, VCHEIGHT/3+45, VCWIDTH, VCHEIGHT*2/3-45)];
    self.scroll.contentSize = CGSizeMake(VCWIDTH*3, 0);
    self.scroll.delegate = self;
    self.scroll.pagingEnabled = YES;
    self.scroll.tag = 200;
    [self.view addSubview:self.scroll];
    
    self.detailMajorTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, VCWIDTH, VCHEIGHT*2/3-45)style:(UITableViewStyleGrouped)];
    self.detailMajorTableView.dataSource = self;
    self.detailMajorTableView.delegate = self;
    self.detailMajorTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.detailMajorTableView.showsVerticalScrollIndicator = NO;
    self.detailMajorTableView.tag = 201;
    [self.scroll addSubview:self.detailMajorTableView];

    self.employmentTV = [[UITableView alloc]initWithFrame:CGRectMake(VCWIDTH, 0, VCWIDTH, VCHEIGHT*2/3-45)style:(UITableViewStyleGrouped)];
    self.employmentTV.delegate = self;
    self.employmentTV.dataSource = self;
    self.employmentTV.showsVerticalScrollIndicator = NO;
    self.employmentTV.tag = 202;
    [self.scroll addSubview:self.employmentTV];
    
    self.recommendTableView = [[UITableView alloc]initWithFrame:CGRectMake(VCWIDTH*2, 0, VCWIDTH, VCHEIGHT*2/3-45) style:(UITableViewStylePlain)];
    self.recommendTableView.dataSource = self;
    self.recommendTableView.delegate = self;
    self.recommendTableView.showsVerticalScrollIndicator = NO;
    self.recommendTableView.tag = 203;
    [self.scroll addSubview:self.recommendTableView];
    
    GKZYSortLeftBarButtonItemView *back = [[GKZYSortLeftBarButtonItemView alloc]initWithFrame:CGRectMake(16, 28, 60, 30)];
    [back setTitleColor:[UIColor whiteColor] andImage:[UIImage imageNamed:@"10enter-my@3x"]];
     UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(back)];
    [back addGestureRecognizer:tap4];
    [self.view addSubview:back];
    
    
}

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:YES];
    self.navigationController.navigationBar.alpha = 0;
    self.tabBarController.tabBar.alpha = 0;
    self.navigationItem.title = self.model.major_name;

}


-(void)viewDidLoad{

    [super viewDidLoad];
    GKZYSortLeftBarButtonItemView *leftBBI = [[GKZYSortLeftBarButtonItemView alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];
    UITapGestureRecognizer *tap6 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(back)];
    [leftBBI addGestureRecognizer:tap6];
    UIBarButtonItem *bar = [[UIBarButtonItem alloc]initWithCustomView:leftBBI];
    self.navigationItem.leftBarButtonItem = bar;
    
    [self makeData0];
   
    [self makeData1];
    
    [self makeData2];
    
}

#pragma mark ++++++++++  数据解析  ++++++++++++

-(void)makeData0{

    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.dimBackground = YES;
    HUD.labelText = @"请稍等";
    [HUD showAnimated:YES whileExecutingBlock:^{
        [self dataRequest0];
    } completionBlock:^{
        
        [HUD removeFromSuperview];
        HUD = nil;
    }];
}


-(void)makeData2{

    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.dimBackground = YES;
    HUD.labelText = @"请稍等";
    [HUD showAnimated:YES whileExecutingBlock:^{
        [self dataRequest2];
    } completionBlock:^{
        
        [HUD removeFromSuperview];
        HUD = nil;
    }];
}


-(void)makeData1{
    HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:HUD];
    HUD.dimBackground = YES;
    HUD.labelText = @"请稍等";
    [HUD showAnimated:YES whileExecutingBlock:^{
        [self dataRequest1];
    } completionBlock:^{
        
        [HUD removeFromSuperview];
        HUD = nil;
    }];
}

-(void)dataRequest0{
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", @"text/plain", nil];
    NSDictionary *parameters = @{@"diploma":self.model.diploma_type,@"wl":SINGLETON.wl,@"major_id":self.model.major_id};
    [manager GET:KdetailMajorURL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        NSDictionary *dictionary = responseObject[@"data"];
        self.majorDetailInfo = [[GKZYMajorDetailModel alloc]init];
        [self.majorDetailInfo setValuesForKeysWithDictionary:dictionary];
        self.similarDataArray = [[NSMutableArray alloc]init];
        NSArray *array = dictionary[@"similar_major_list"];
        for (NSDictionary *dict in array) {
            
            GKZYSimilarMajorModel *model = [[GKZYSimilarMajorModel alloc]init];
            [model setValuesForKeysWithDictionary:dict];
            [self.similarDataArray addObject:model];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.detailMajorTableView reloadData];
        });
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"网络请求失败,错误代码为%@",error);
    }];
}

-(void)dataRequest1{
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", @"text/plain", nil];
    NSDictionary *parameters =@{@"batch":@"bk1",@"loc_name":SINGLETON.loc_name,@"major_id":self.model.major_id,@"score":SINGLETON.score,@"wl":SINGLETON.wl};
    
    [manager POST:KrecommondURL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        self.recommendArray = [[NSMutableArray alloc]init];
        NSDictionary *dictionary = responseObject[@"data"];
        NSArray *array = dictionary[@"sch_list"];
        for (NSDictionary *dict in array) {
            GKZYRecommentSchoolModel *model = [[GKZYRecommentSchoolModel alloc]init];
            [model setValuesForKeysWithDictionary:dict];
            [self.recommendArray addObject:model];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.recommendTableView reloadData];
        });
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"网络请求失败,错误代码为%@",error);
    }];
}

-(void)dataRequest2{
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", @"text/plain", nil];
    
    NSDictionary *parameters = @{@"diploma":self.model.diploma_type,@"wl":SINGLETON.wl,@"major_id":self.model.major_id,@"loc_name":SINGLETON.loc_name};
    
    [manager GET:KemploymentURL parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        NSDictionary *outDict = responseObject[@"data"];
        self.dataDictionary = [[EmploymentDictionaryModel alloc]init];
        
        self.industryArray = [[NSMutableArray alloc]init];
        for (NSDictionary *dict in outDict[@"ind_info_list"]) {
            Industry_info_listModel *model = [[Industry_info_listModel alloc]init];
            [model setValuesForKeysWithDictionary:dict];
            [self.industryArray addObject:model];
        }
        self.dataDictionary.ind_info_list = self.industryArray;
        self.cityArray = [[NSMutableArray alloc]init];
        for (NSDictionary *dict in outDict[@"city_list"]) {
            City_listModel *model = [[City_listModel alloc]init];
            [model setValuesForKeysWithDictionary:dict];
            [self.cityArray addObject:model];
        }
        self.dataDictionary.city_list = self.cityArray;
        
        self.majorSalaryArray = [[NSMutableArray alloc]init];
        for (NSDictionary *dict in outDict[@"major_salary_year_list"]) {
            Major_salary_year_listModel *model = [[Major_salary_year_listModel alloc]init];
            [model setValuesForKeysWithDictionary:dict];
            [self.majorSalaryArray addObject:model];
        }
        self.dataDictionary.major_salary_year_list = self.majorSalaryArray;
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.employmentTV reloadData];
        });
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"网络请求失败,错误代码为%@",error);
    }];
}


#pragma mark ++++++++++++   tap手势事件       +++++++++++++++++


-(void)introduceTB{

    [self.employment setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
    [self.recommend setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
    [self.introduce setTheTitleColor:[UIColor orangeColor] andMarkColor:[UIColor orangeColor]];

    self.scroll.contentOffset = CGPointMake(0, 0);
    
}

-(void)employmentTB{

    [self.introduce setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
    [self.recommend setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
    [self.employment setTheTitleColor:[UIColor orangeColor] andMarkColor:[UIColor orangeColor]];

    self.scroll.contentOffset = CGPointMake(VCWIDTH, 0);
    [self.employmentTV reloadData];
}

-(void)recommendTB{

    [self.employment setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
    [self.introduce setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
    [self.recommend setTheTitleColor:[UIColor orangeColor] andMarkColor:[UIColor orangeColor]];
    self.scroll.contentOffset = CGPointMake(VCWIDTH*2, 0);
}

-(void)back{
    
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBar.alpha = 1;
    self.tabBarController.tabBar.alpha = 1;
    [self.backLabel removeFromSuperview];
    
}


#pragma mark ++++++++++++    scrollView代理方法    ++++++++++++++++++

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    if (scrollView.tag == 200) {
    
        if (scrollView.contentOffset.x == 0) {
        
        [self.employment setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
        [self.recommend setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
        [self.introduce setTheTitleColor:[UIColor orangeColor] andMarkColor:[UIColor orangeColor]];

    }else if (scrollView.contentOffset.x == VCWIDTH){
        
        [self.introduce setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
        [self.recommend setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
        [self.employment setTheTitleColor:[UIColor orangeColor] andMarkColor:[UIColor orangeColor]];
        
    }else{
        
        [self.employment setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
        [self.introduce setTheTitleColor:[UIColor colorWithWhite:0.1 alpha:0.5] andMarkColor:[UIColor clearColor]];
        [self.recommend setTheTitleColor:[UIColor orangeColor] andMarkColor:[UIColor orangeColor]];
    }
  }
}


-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    CGFloat displacement = scrollView.contentOffset.y;
    
    switch (scrollView.tag ) {
        case 203:
        {
            if (scrollView.tag == 203) {
                if (self.recommendArray.count  <= 4) {
                    self.topView.frame = CGRectMake(0, 0, VCWIDTH, VCHEIGHT/3);
                    self.scroll.frame = CGRectMake(0, VCHEIGHT/3+45, VCWIDTH, VCHEIGHT*2/3-45);
                    self.introduce.frame = CGRectMake(0, 64, VCWIDTH/3, 40);
                    self.employment.frame = CGRectMake(VCWIDTH/3, 64, VCWIDTH/3, 40);
                    self.recommend.frame = CGRectMake(VCWIDTH*2/3, 64, VCWIDTH/3, 40);
                    self.introduce.frame = CGRectMake(0, VCHEIGHT/3, VCWIDTH/3, 40);
                    self.employment.frame = CGRectMake(VCWIDTH/3, VCHEIGHT/3, VCWIDTH/3, 40);
                    self.recommend.frame = CGRectMake(VCWIDTH*2/3, VCHEIGHT/3, VCWIDTH/3, 40);
                    self.navigationController.navigationBar.alpha = 0;
                }else{
                    if (displacement >= VCHEIGHT/3-64) {
                        
                        self.topView.frame = CGRectMake(0, -VCHEIGHT/3+64, VCWIDTH, VCHEIGHT/3);
                        self.scroll.frame = CGRectMake(0, 109, VCWIDTH, VCHEIGHT-109);
                        self.introduce.frame = CGRectMake(0, 64, VCWIDTH/3, 40);
                        self.employment.frame = CGRectMake(VCWIDTH/3, 64, VCWIDTH/3, 40);
                        self.recommend.frame = CGRectMake(VCWIDTH*2/3, 64, VCWIDTH/3, 40);
                        self.navigationController.navigationBar.alpha = 1;
                        
                        self.detailMajorTableView.frame = CGRectMake(0, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                        self.employmentTV.frame = CGRectMake(VCWIDTH, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                        self.recommendTableView.bounces = YES;
                        self.recommendTableView.frame = CGRectMake(VCWIDTH*2, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                        
                    }else if(displacement < 0){
                        
                        self.topView.frame = CGRectMake(0, 0, VCWIDTH, VCHEIGHT/3);
                        self.topView.image.frame = CGRectMake(displacement, displacement, VCWIDTH-2*displacement, VCHEIGHT/3-2*displacement);
                        self.scroll.frame = CGRectMake(0, VCHEIGHT/3+45-displacement, VCWIDTH, VCHEIGHT*2/3-45);
                        self.introduce.frame = CGRectMake(0, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                        self.employment.frame = CGRectMake(VCWIDTH/3, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                        self.recommend.frame = CGRectMake(VCWIDTH*2/3, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                        self.recommendTableView.bounces = YES;
                        scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
                        
                    }else{
                        
                        self.topView.frame = CGRectMake(0, -displacement, VCWIDTH, VCHEIGHT/3);
                        self.scroll.frame = CGRectMake(0, VCHEIGHT/3 +45-displacement, VCWIDTH, VCHEIGHT *2/3 -45+displacement);
                        self.detailMajorTableView.frame = CGRectMake(0, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                        self.employmentTV.frame = CGRectMake(VCWIDTH, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                        self.recommendTableView.frame = CGRectMake(VCWIDTH*2, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                        self.navigationController.navigationBar.alpha = 0;
                        self.introduce.frame = CGRectMake(0, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                        self.employment.frame = CGRectMake(VCWIDTH/3, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                        self.recommend.frame = CGRectMake(VCWIDTH*2/3, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                        self.recommendTableView.bounces = NO;
                        if (displacement == 0) {
                            self.recommendTableView.bounces = YES;
                        }
                    }
                }
            }
        }
            break;
            
        default:
        {
            if (displacement >= VCHEIGHT/3-64) {
           
                self.topView.frame = CGRectMake(0, -VCHEIGHT/3+64, VCWIDTH, VCHEIGHT/3);
                self.scroll.frame = CGRectMake(0, 109, VCWIDTH, VCHEIGHT-109);
                self.introduce.frame = CGRectMake(0, 64, VCWIDTH/3, 40);
                self.employment.frame = CGRectMake(VCWIDTH/3, 64, VCWIDTH/3, 40);
                self.recommend.frame = CGRectMake(VCWIDTH*2/3, 64, VCWIDTH/3, 40);
                self.navigationController.navigationBar.alpha = 1;
                
                self.detailMajorTableView.frame = CGRectMake(0, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                self.employmentTV.frame = CGRectMake(VCWIDTH, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                self.recommendTableView.frame = CGRectMake(VCWIDTH*2, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                
            }else if(displacement < 0){
                
                self.topView.frame = CGRectMake(0, 0, VCWIDTH, VCHEIGHT/3);
                self.topView.image.frame = CGRectMake(displacement, displacement, VCWIDTH-2*displacement, VCHEIGHT/3-2*displacement);
                self.scroll.frame = CGRectMake(0, VCHEIGHT/3+45-displacement, VCWIDTH, VCHEIGHT*2/3-45);
                self.introduce.frame = CGRectMake(0, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                self.employment.frame = CGRectMake(VCWIDTH/3, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                self.recommend.frame = CGRectMake(VCWIDTH*2/3, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

            }else{
                
                self.topView.frame = CGRectMake(0, -displacement, VCWIDTH, VCHEIGHT/3);
                self.scroll.frame = CGRectMake(0, VCHEIGHT/3 +45-displacement, VCWIDTH, VCHEIGHT *2/3 -45+displacement);
                self.detailMajorTableView.frame = CGRectMake(0, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                self.employmentTV.frame = CGRectMake(VCWIDTH, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                self.recommendTableView.frame = CGRectMake(VCWIDTH*2, 0, VCWIDTH, CGRectGetHeight(self.scroll.frame));
                self.navigationController.navigationBar.alpha = 0;
                self.introduce.frame = CGRectMake(0, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                self.employment.frame = CGRectMake(VCWIDTH/3, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                self.recommend.frame = CGRectMake(VCWIDTH*2/3, VCHEIGHT/3-displacement, VCWIDTH/3, 40);
                scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

            }
        }
            break;
    }
}


#pragma mark ++++++++++    tableView代理方法   +++++++++++++

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    switch (tableView.tag) {
        case 201:{
          return self.similarDataArray.count;
        }
            break;
        case 202:{
            return 1;
        }
            break;
        default:{
            return self.recommendArray.count;
        }
            break;
    }
}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    if (tableView.tag == 201 && self.majorDetailInfo != nil) {
        self.headerView = [GKZYMajorDetailHeaderView configureTheHeaderViewWithModel:self.majorDetailInfo andOpneOrPickUp:self.openOrPickUp];
        [self.headerView.openOrPickButton addTarget:self action:@selector(openOrPickUpAction) forControlEvents:(UIControlEventTouchUpInside)];
        return self.headerView;
    }else{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, VCWIDTH, 0.01)];
        return view;
    }
    return nil;
}

//专业详情是否展开
-(void)openOrPickUpAction{

    self.openOrPickUp = !self.openOrPickUp;
    if (!self.openOrPickUp ) {
        CGPoint point = CGPointMake(0, 0);
        self.detailMajorTableView.contentOffset = point;
    }
   
    [self.detailMajorTableView reloadData];
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    if (tableView.tag == 201) {
        return [self tableView:tableView viewForHeaderInSection:section].frame.size.height ;
    }
    
    return 0.1;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (tableView.tag) {
        case 201:{
            return 40;
        }
            break;
        case 202:{
            return 800;
        }
            break;
        default:{
            return 80;

        }
            break;
    }
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    switch (tableView.tag) {
        case 201:{
            
            GKZYMajorDetailTableViewCell *cell = [[GKZYMajorDetailTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
            GKZYSimilarMajorModel *model = self.similarDataArray[indexPath.row];
            [cell configureTheCellWithModel:model];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            return cell;
        }
            break;
        case 202:{
            
                GKZYMajorEmploymentTableViewCell *cell =[[GKZYMajorEmploymentTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"ecell"];
            
                if (self.dataDictionary != nil) {
                    cell.model = self.dataDictionary;
                  
                }
                    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
                    return cell;
        }
            break;
        default:{
//            GKZYRecommendTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"recommendCell"];
//            if (cell == nil) {
//                cell = [[GKZYRecommendTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"recommendCell"];
//            }
           GKZYRecommendTableViewCell *cell = [[GKZYRecommendTableViewCell alloc]initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"recommendCell"];
            GKZYRecommentSchoolModel *model = self.recommendArray[indexPath.row];
            [cell configureTheCellWithModel:model andOrder:indexPath.row];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
    
        }
            break;
    }
}



-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    switch (tableView.tag) {
        case 201:{
            GKZYSortMajorDetailViewController *majorVC = [[GKZYSortMajorDetailViewController alloc]init];
            GKZYMajorQueryModel *model = [[GKZYMajorQueryModel alloc]init];
            GKZYSimilarMajorModel *similarM = self.similarDataArray[indexPath.row];
            model.major_name = similarM.major_name;
            model.major_id = similarM.major_id;
            model.major_code = similarM.major_code;
            model.diploma_type = similarM.diploma_type;
            majorVC.model = model;
            [self.navigationController pushViewController:majorVC animated:YES];
        }
            break;
        case 202:{
            
        }
            break;
        default:{
            GKZYUniversityDetailController *universityVC = [[GKZYUniversityDetailController alloc]init];
            GKZYRecommentSchoolModel *model = self.recommendArray[indexPath.row];
            universityVC.sch_id = model.sch_id;
            [self.navigationController pushViewController:universityVC animated:YES];
        }
            break;
    }
}

@end
